{extend name='public/layout' /}
{block name='content'}
<style>
    .main{padding:10px;background-color: #fff;}
</style>
<div class="main ">
    <div class="ylj-box ylj-padding-t-b ylj-margin-b">
        <form action="{:url('loginDo')}" method="post" id="form" class="am-form" >
            <div class="am-form-group am-form-icon">
                <i class="am-icon-user"></i>
                <input type="text" name="username" id="username" class="am-form-field" placeholder="用户名或手机号码">
            </div>

            <div class="am-form-group am-form-icon">
                <i class="am-icon-lock"></i>
                <input type="password" name="password" id="password" class="am-form-field" placeholder="密码">
            </div>
            <div class="am-form-group am-form-icon">
                <i class="am-icon-image"></i>
                <input type="text" class="am-form-field" name="code" id="code" style="padding-right:140px;" placeholder="验证码">
                <img src="{:captcha_src()}" id="code_img" alt="" class="am-fr" style="position:absolute;top:0;right:2px;height:35px;">
            </div>
            <div class="am-form-group">
                <a href="{:url('pass')}">忘记密码?</a>
                <a href="{:url('reg')}" class="am-fr">注册账号</a>
            </div>
            <div class="am-form-group">
                <button id="ylj-sub-btn" type="button" class="am-btn ylj-btn-color am-btn-block am-round">立即登录</button>
            </div>
            <input type="hidden" name="forward" value="{$forward}">
        </form>
    </div>

</div>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script src="__PUBLIC__/js/plugins/jquery.ajax.form.js"></script>
<script>
    $(function(){
        $("#code_img").click(function(){
            var timenow = new Date().getTime();
            $('#code_img').attr("src","{:captcha_src()}?t"+timenow)
        });
        $('#ylj-sub-btn').click(function(){
            var username   = $("#username").val();
            var password = $("#password").val();
            var code     = $("#code").val();
            var reg      = /^1[34578][0-9]{9}$/;
            if(username.length = 0){
                layer.msg('请填写用户名',{icon:2});
                return false;
            }
            if(password.length == 0){
                layer.msg('请填写密码',{icon:2});
                return false;
            }
            if(code.length == 0){
                layer.msg('请填写验证码',{icon:2});
                return false;
            }
            $('#form').submit();
        });
        $('#form').ajaxForm({success:complate,dataType:'json'});
        function complate(result){
            if(result.status == 1){
                window.location.href = result.uri;
            } else {
                layer.msg(result.msg,{icon:2});
            }
        }
    });
</script>
{/block}